package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class MainActivity extends AppCompatActivity {

    EditText name, pas;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name = findViewById(R.id.name);
        pas = findViewById(R.id.pas);
        button = findViewById(R.id.button);
        SharedPreferences sp = getSharedPreferences("three", MODE_PRIVATE);
        String s1 = sp.getString("name", "");
        String s2 = sp.getString("pas", "");
        name.setText(s1);
        pas.setText(s2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String n = String.valueOf(name.getText());
                String p = String.valueOf(pas.getText());
                if ("admin".equals(n)&&"123456".equals(p)){
                   SharedPreferences sp = getSharedPreferences("three", MODE_PRIVATE);
                   SharedPreferences.Editor edit =sp.edit();
                   edit.putString("name", n);
                   edit.putString("pas", p);
                   edit.commit();
                }else {
                    Toast.makeText(MainActivity.this, "账号密码错误", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}